 #include<reg51.h>
 #include<stdio.h>
#include<string.h>
 #define LCD_clear() LCD_command(0x01)	/* Clear display LCD */
 #define LCD_origin() LCD_command(0x02)	/* Set to origin LCD */
 #define LCD_row1() LCD_command(0x80)	/* Begin at Line 1 */
 #define LCD_row2() LCD_command(0xC0) 
  
void serial_tx();
sbit rs =P3^6;
sbit en =P3^7;
int mybyte;

char serial_rx()
  {
	int x;
	while(RI == 0);
	 {
	  x++;
	  if(x==1000)
  serial_tx();
	 }
	mybyte=SBUF;
	RI = 0;
	return (mybyte);
}
void delay1()
	{
	int y = 100;
	while(y--);
	} 

void serial_tx()
	{
	SBUF = mybyte;
	while(TI == 0);
	TI = 0;
	delay1();
	}

void wait_state1(unsigned int y)
            {
              unsigned int i,j;
              for(i=0;i<y;i++)
               for(j=0;j<498;j++);
            }
          


void baud_init()
{
	TMOD = 0x20;
	TH1 = 0xFD;
	SCON = 0x50;
	TR1 = 1;
}

void lcd_en ()
{
//		rw=0;
		en  = 1; en  = 1; en  = 1;
      en  = 0; en  = 0;
}
void LCD_delay(unsigned char ms)
{
	unsigned int n;
	unsigned int i;
	for (n=0; n<ms; n++)
	{
		for (i=0; i<1535; i++); /* For 1 ms */
	}
    
}
 
void LCD_command(unsigned char command)
{
    //  rw=0;
      rs=0; rs = 0;
  	   P0		= command;
  	   lcd_en ();
      LCD_delay(1);

}

void LCD_init()
 {
 	//   rw=0;
 	   LCD_command(0x38);
 	   LCD_command(0x06);
 	   LCD_command(0x0c);
 	   LCD_command(0x01);
      LCD_delay(06);
 }
 
void LCD_putc(unsigned char ascii)
{     
 //    rw=0;
 		rs=1;
  	   P0		= ascii;
  	   lcd_en ();
      LCD_delay(2);
//      LCD_command(0x0C);
}

 
void LCD_puts(unsigned char *lcd_string)
{
	while (*lcd_string) 
	{
		LCD_putc(*lcd_string++);
	}
}
void disp(unsigned int name1)
    	 {
 	        rs=0x01;
  			  P0=name1;
  			  lcd_en ();
 			  delay1();
 	   	}
void main()
   {
      char i=0,s; 
      char ser[21];
//      char serial_no1[21];
//      char temp1[]={'B','6','D','2','D','B','D','7','\0'};
//      unsigned char a[]={'1','2','9','2','2','1','8','4','\0'};
  
  //    unsigned char b[]={'1','2','9','1','4','9','7','4','\0'};
    //  unsigned char c[]={'1','2','9','0','7','5','8','4','\0'};
         unsigned char a[]={'1','2','9','2','2','1','8','4','\0'};

      
    //  baud_init();
      LCD_init();
      LCD_command(0x80);  
      LCD_puts("DIP CARD");
    //  serial_tx();
       while(1)
           {
           
      while(i<=8)
       {
        baud_init();
        ser[i]=serial_rx();
        i++;
        }
        
   //    disp(*ser); 
     printf("no=%d",ser);   
       /* if(*ser==*a)
           { 
            
            
            
            
            LCD_command(0xc0);  
            LCD_puts("CARD Match");
           }
          else
           {
           
            LCD_command(0xc0);  
            LCD_puts("CARD Mis Mat");
           }
         while(1); */ 

           /*gets(ser);
           i = strcmp(a,ser);  
          if(i==0)
           {
            LCD_command(0xc0);
            LCD_puts("card match A");
            wait_state1(10000);
           
           }
           else
           {
            LCD_command(0xc0);
            LCD_puts("card Not match");
            wait_state1(10000);
           
           
           }*/
        
        
           }


}

 
  
    	
  
	 



 
             

 
   
     
